package test_3_13;

import java.util.Scanner;

public class two {
    public static void main(String[] args) {
        int[] arr = new int[]{1, 2, 3, 4, 5, 6, 7};
        int left = 0;
        int right = arr.length - 1;
        System.out.println("请输入你要查询的数字：");
        Scanner sc = new Scanner(System.in);
        int key = sc.nextInt();
        while (left <= right) {
            int mid = (left + right) / 2;
            if (key > arr[mid]) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }
            left++;
            right--;
        }
        if (key==arr[left]) {
            System.out.println("找到了：" +(left) );
        }
      else
       {
            System.out.println("未找到");
        }
    }


}
